<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../include/base.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>欢迎使用CRM管理系统</title>
<link rel="stylesheet" href="${basePath }/css/bootstrap.min.css"
	type="text/css" />
<link rel="stylesheet" href="${basePath }/css/style.css" type="text/css" />
<script type="text/javascript" src="${basePath }/js/jquery.min.js"></script>
<script type="text/javascript" src="${basePath }/My97/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath }/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="navbar">
		<div class="navbar-inner">
			<div class="container">
				<a href="${basePath }/message" class="brand">凯盛CRM管理系统</a>
				<div class="nav-collapse">
					<ul class="nav">
						<li><a href="${basePath }/message">最新动态</a></li>
						<li class="active"><a href="${basePath }/contacts/list">联系人</a>
						</li>
						<li><a href="${basePath }/task/list">日程安排</a></li>
						<li><a href="${basePath }/deal/list">业务机会</a></li>
					</ul>
					<ul class="nav pull-right">
						<li><a href="#">${user.username }</a></li>
						<li class="divider-vertical"></li>
						<li><a href="${basePath }/user/info">账号设置</a></li>
						<li><a href="${basePath }/user/loginout">退出</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div id="content" class="container">
		<div class="span9">
			<ul class="breadcrumb" style="vertical-align:top">
				<li class="active">联系人和公司详情</li>
			</ul>
			<div class="well">
				<div>
					<table id="table">
						<c:choose>
							<c:when test="${contacts.name == null }">
								<tr style="border-bottom:0px;">
									<td style="width:80px"><a
										href="${basePath }/contacts/detail?id=${contacts.id }"> <img
											src="${basePath }/img/company.png" alt="ss" /> </a>
									</td>
									<td style="width:784px">
										<h3>
											<a href="${basePath }/contacts/detail?id=${contacts.id }">${contacts.companyName
												}</a>
										</h3>
										<h6>${contacts.address }</h6>
									</td>
								</tr>
							</c:when>
							<c:otherwise>
								<tr>
									<td style="width:80px"><img
										src="${basePath }/img/contacts.png" alt="${contacts.name }" />
									</td>
									<td style="width:784px">
										<h3>${contacts.name }</h3>
										<h6>
											${contacts.title } <a
												href="${basePath }/contacts/detail?id=${contacts.contacts.id }">${contacts.companyName
												}</a>
										</h6>
									</td>
								</tr>
							</c:otherwise>
						</c:choose>
					</table>
				</div>
				<ul class="nav nav-tabs" style="margin-top:20px">
					<li class="active"><a data-toggle="tab" href="#note">记录</a>
					</li>
					<li class=""><a data-toggle="tab" href="#deal">业务机会</a>
					</li>
				</ul>
				<div id="myTabContent" class="tab-content">
					<div id="note" class="tab-pane fade active in">
						<h4>添加一个关于ss的记录</h4>
						<form action="save-note" method="post" style="margin-bottom:50px">
							<textarea style="width:650px" rows="3"
								name="contactsNote.content"></textarea>
							<button type="submit" class="btn pull-right">添加</button>
						</form>
						<c:forEach var="note" items="${contacts.contactsNoteSet }"
							varStatus="status">
							<blockquote>
								<a href="#">${note.user.username }</a>:${note.content }<br /> <br />
								<small> <a href="#re" data-toggle="collapse"
									data-target="#re${status.count }">回复</a> <span
									class="pull-right">发布于 ${note.createTime }</span> </small>
							</blockquote>
							<div id="re${status.count }" class="collapse">
								<form action="save-note" method="post">
									<input type="hidden" name="noteid" value="${note.id }" />
									<div class="input-append">
										<input type="text" class="input-xxlarge"
											name="contactsNote.content" />
										<button type="submit" class="btn">回复</button>
									</div>
								</form>
							</div>
						</c:forEach>
					</div>
					<div id="deal" class="tab-pane fade">
						<a href="#myDealModal" class="btn btn-success btn-large" data-toggle="modal">添加一个新业务机会</a>
						<br />
						<div style="margin-top:20px">
							<table id="table">
								<c:forEach var="deal" items="${dealList}">
									<tr>
										<td style="width:130px"><c:choose>
												<c:when test="${deal.state eq '创建' }">
													<span class="label label-info">追踪</span>
												</c:when>
												<c:when test="${deal.state eq '成功' }">
													<span class="label label-success">${deal.state }</span>
												</c:when>
												<c:when test="${deal.state eq '失败' }">
													<span class="label">${deal.state }</span>
												</c:when>
												<c:when test="${deal.state eq '追踪' }">
													<span class="label label-info">${deal.state }</span>
												</c:when>
											</c:choose>
										</td>
										<td style="width:734px"><strong><a
												href="${basePath }/deal/deal-detail?id=${deal.id}">${deal.title
													}</a> </strong><br /> 负责人：${deal.user.username }<br>
											内容:${deal.content }<br /> 创建时间：${deal.createTime }<br />
										</td>
									</tr>
								</c:forEach>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="span3">
			<c:choose>
				<c:when test="${contacts.name == null }">
					<a href="${basePath }/contacts/edit-company?id=${contacts.id }"
						class="btn btn-danger">编辑公司</a>
					<br />
					<br />
				</c:when>
				<c:otherwise>
					<a href="${basePath }/contacts/edit?id=${contacts.id }"
						class="btn btn-danger">编辑联系人</a>
					<br />
					<br />
					<div class="box well">
						<div class="head">任务</div>
						<ul>
							<c:forEach items="${taskList }" var="task">
								<li>${task.title } <c:choose>
										<c:when test="${task.complete eq true }">
				                			(已完成)
				                		</c:when>
										<c:otherwise>
				                			(未完成)
				                		</c:otherwise>
									</c:choose>
								</li>
							</c:forEach>
							<a href="#myModal" data-toggle="modal">添加一个新任务</a>
						</ul>
					</div>
				</c:otherwise>
			</c:choose>
			<div class="box well">
				<div class="head">联系人或公司详情</div>
				<ul style="list-style-type:none">
					<c:if test="${contacts.telSet.size() != 0 }">
						<div>
							电话：<br />
							<c:forEach items="${contacts.telSet }" var="tel">
								<li>${tel.tel } (${tel.type })</li>
							</c:forEach>
						</div>
					</c:if>
					<c:if test="${contacts.mailSet.size() != 0 }">
						<div>
							邮箱：<br />
							<c:forEach items="${contacts.mailSet }" var="mail">
								<li>${mail.mail } (${mail.type })</li>
							</c:forEach>
						</div>
					</c:if>
					<div>
						<c:if test="${fn:length(contacts.weibo) != 0 }">
							<li>微博：${contacts.weibo }</li>
						</c:if>
						<c:if test="${fn:length(contacts.im) != 0 }">
							<li>QQ：${contacts.im }</li>
						</c:if>
						<c:if test="${fn:length(contacts.website) != 0 }">
							<li>主页：${contacts.website }</li>
						</c:if>
						<c:if test="${fn:length(contacts.address) != 0 }">
							<li>地址：${contacts.address }</li>
						</c:if>
					</div>
				</ul>
			</div>
		</div>
	</div>
	<form class="form-horizontal" action="${basePath }/task/edit-save"
		method="post" id="edit-form">
		<div class="modal fade hide" id="myModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">×</button>
				<h3>添加关于${contacts.name }的任务</h3>
			</div>
			<div class="modal-body">
				<fieldset>
					<input type="hidden" name="contactsId" value="${contacts.id }">
					<div class="control-group">
						<label class="control-label">任务</label>
						<div class="controls">
							<input type="text" name="task.title">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">选择负责人</label>
						<div class="controls">
							<select name="userId">
								<c:forEach var="user" items="${userList}">
									<option value="${user.id }" id="${user.id }">${user.username
										}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">开始时间</label>
						<div class="controls">
							<input type="text"
								onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
								name="task.startDate">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">结束时间</label>
						<div class="controls">
							<input type="text"
								onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
								name="task.endDate">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">任务类型</label>
						<div class="controls">
							<select name="taskTypeId">
								<c:forEach var="tasktype" items="${taskType }">
									<option value="${tasktype.id }" id="${tasktype.id }">${tasktype.type
										}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">可见性</label>
						<div class="controls">
							<label class="checkbox"> <input name="task.all"
								type="checkbox" id="all">是否所有人可见 </label>
						</div>
					</div>
				</fieldset>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" type="submit">保存</button>
				<a href="#" class="btn" data-dismiss="modal">关闭</a>
			</div>
		</div>
	</form>
	<form id="myform" class="form-horizontal"
		action="${basePath }/deal/deal-save" method="post">
		<div class="modal fade hide" id="myDealModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">×</button>
				<h3>添加关于${contacts.name }的业务机会</h3>
			</div>
			<div class="modal-body">
				<fieldset>
					<input type="hidden" name="contactsId" value="${contacts.id }">
					<div class="control-group" id="titleDiv">
						<label class="control-label" for="name">标题</label>
						<div class="controls">
							<input type="text" id="title" class="input-xlarge"
								name="deal.title">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="company">负责人</label>
						<div class="controls">
							<select name="userId" style="width:280px;">
								<option>--选择负责人--</option>
								<c:forEach var="user" items="${userList}">
									<option value="${user.id }">${user.username }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="company">类型</label>
						<div class="controls">
							<select name="dealTypeId" style="width:280px;" id="typeSelect">
								<option>--选择类型--</option>
								<c:forEach var="dealType" items="${dealTypeList}">
									<option value="${dealType.id }">${dealType.type}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="name">价值</label>
						<div class="controls">
							<input type="text" class="input-xlarge" name="deal.money">
						</div>
					</div>
					<div class="control-group" id="contentDiv">
						<label class="control-label" for="Introduction">内容</label>
						<div class="controls">
							<textarea id="content" name="deal.content" class="input-xlarge"
								rows="6"></textarea>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">谁可以看到</label>
						<div class="controls">
							<label class="radio"> <input type="radio" name="view"
								value="all" />所有人<br /> </label> <label class="radio"> <input
								type="radio" name="view" value="me" />只有我<br /> </label> <label
								class="radio"> <input type="radio" name="view"
								value="group" data-toggle="collapse" data-target="#group"
								data-parent="#detail" />选择一个组<br /> </label>
							<div id="group" class="collapse">
								<select name="group" style="width:150px">
									<option value="">--请选择一个分组--</option>
									<c:forEach items="${userGroupList }" var="group">
										<option value="${group.id }">${group.groupName }</option>
									</c:forEach>
								</select>
							</div>
							<label class="radio"> <input type="radio" name="view"
								value="people" data-toggle="collapse" data-target="#people"
								data-parent="#detail" />选择一些人<br /> </label>
							<div id="people" class="collapse">
								<c:forEach items="${userList }" var="user">
									<input type="checkbox" name="people" value="${user.id }" />${user.username }
		                              </c:forEach>
							</div>
						</div>
					</div>
				</fieldset>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" type="submit">保存</button>
				<a href="#" class="btn" data-dismiss="modal">关闭</a>
			</div>
		</div>
	</form>
</body>
</html>
